<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI对话助手</title>
    <script src="https://hoppinzq.com/static/js/vendor/jquery-3.5.1.min.js"></script>
    <script src="../ai.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background-color: #f5f5f5;
            color: #333;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        
        .chat-container {
            width: 100%;
            max-width: 800px;
            height: 90vh;
            background-color: white;
            border-radius: 15px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        
        .chat-header {
            padding: 20px;
            background-color: #4a6fa5;
            color: white;
            text-align: center;
            border-bottom: 1px solid #ddd;
        }
        
        .chat-header h1 {
            font-size: 24px;
            margin-bottom: 5px;
        }
        
        .chat-header p {
            font-size: 14px;
            opacity: 0.9;
        }
        
        .chat-messages {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
            background-color: #f9f9f9;
        }
        
        .message {
            margin-bottom: 15px;
            padding: 10px 15px;
            border-radius: 10px;
            max-width: 80%;
            word-wrap: break-word;
            animation: fadeIn 0.3s ease;
            position: relative;
        }
        
        .user-message {
            background-color: #4a5568;
            color: white;
            margin-left: auto;
        }
        
        .ai-message {
            background-color: #e0e0e0;
            color: #333;
            margin-right: auto;
            transition: all 0.2s ease;
        }
        
        .message-time {
            font-size: 12px;
            opacity: 0.7;
            margin-top: 5px;
            text-align: right;
        }
        
        .ai-message .message-time {
            text-align: left;
        }
        
        .chat-input-area {
            padding: 20px;
            background-color: white;
            border-top: 1px solid #ddd;
            display: flex;
            gap: 10px;
        }
        
        .chat-input {
            flex: 1;
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 25px;
            font-size: 16px;
            outline: none;
            transition: border-color 0.3s;
        }
        
        .chat-input:focus {
            border-color: #4a6fa5;
        }
        
        .send-message {
            padding: 10px 20px;
            background-color: #4a6fa5;
            color: white;
            border: none;
            border-radius: 25px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        
        .send-message:hover {
            background-color: #3a5a85;
        }
        
        .send-message:disabled {
            background-color: #ccc;
            cursor: not-allowed;
        }
        
        .system-message {
            text-align: center;
            margin: 10px 0;
            font-size: 12px;
            color: #666;
            font-style: italic;
        }
        
        /* 工具调用样式 */
        .tool-use {
            background-color: #f0f4f8;
            border: 1px solid #cbd5e0;
            border-radius: 8px;
            padding: 10px;
            margin: 8px 0;
            font-family: monospace;
            font-size: 14px;
            color: #2d3748;
            white-space: pre-wrap;
            overflow-x: auto;
            transition: all 0.2s ease;
        }
        
        .tool-use:hover {
            background-color: #e2e8f0;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .typing-indicator {
            display: flex;
            align-items: center;
            margin-right: auto;
            padding: 10px 15px;
            background-color: #e0e0e0;
            border-radius: 10px;
        }
        
        .typing-dot {
            width: 8px;
            height: 8px;
            background-color: #666;
            border-radius: 50%;
            margin: 0 2px;
            animation: typing 1.4s infinite ease-in-out;
        }
        
        .typing-dot:nth-child(1) {
            animation-delay: 0s;
        }
        
        .typing-dot:nth-child(2) {
            animation-delay: 0.2s;
        }
        
        .typing-dot:nth-child(3) {
            animation-delay: 0.4s;
        }
        
        @keyframes typing {
            0%, 60%, 100% {
                transform: translateY(0);
            }
            30% {
                transform: translateY(-5px);
            }
        }
        
        /* 滚动条样式 */
        .chat-messages::-webkit-scrollbar {
            width: 8px;
        }
        
        .chat-messages::-webkit-scrollbar-track {
            background: #f1f1f1;
        }
        
        .chat-messages::-webkit-scrollbar-thumb {
            background: #888;
            border-radius: 4px;
        }
        
        .chat-messages::-webkit-scrollbar-thumb:hover {
            background: #555;
        }
    </style>
    <script src="https://hoppinzq.com/static/js/vendor/jquery-3.5.1.min.js"></script>
</head>
<body>
    <div class="chat-container">
        <div class="chat-header">
            <h1>AI对话助手</h1>
            <p>使用本地Ollama API进行智能对话</p>
        </div>
        <div class="chat-messages" id="chat-messages">
            <div class="system-message">AI助手已就绪，可以开始对话了！</div>
        </div>
        <div class="chat-input-area">
            <input type="text" class="chat-input" id="message-input" placeholder="输入您的问题..." autocomplete="off">
            <button class="send-message" id="send-message">发送</button>
        </div>
    </div>

    <script src="../chat.js"></script>
    <script>
        // 确保chatHistory初始化
        if (typeof chatHistory === 'undefined') {
            var chatHistory = [];
        }
        
        // 发送聊天消息
        $('#send-message').click(function() {
            const message = $('#message-input').val().trim();
            if (message) {
                sendAIMessage(message);
                $('#message-input').val('');
            }
        });
        
        // 按Enter发送消息
        $('#message-input').keypress(function(e) {
            if (e.which === 13) {
                $('#send-message').click();
            }
        });
    </script>
</body>
</html>